package com.gitee.wsl.compose.modifier.state

import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp


fun Modifier.drawSelectBorder(
    isShowSelected: Boolean = false,
    drawLeft: Boolean = false, // 是否绘制左边框
    drawRight: Boolean = false // 是否绘制右边框
): Modifier = this.drawBehind {
    if (isShowSelected&&(drawLeft||drawRight)){
        val strokeWidth = 1.5.dp.toPx() // 边框宽度
        val inset = strokeWidth/2

        // 绘制左边框
        if (drawLeft) {
            drawLine(
                color = Color.Black,
                start = Offset(inset, inset),
                end = Offset(inset, size.height - inset),
                strokeWidth = strokeWidth
            )
        }

        // 绘制上边框
        drawLine(
            color = Color.Black,
            start = Offset(0f, inset),
            end = Offset(size.width, inset),
            strokeWidth = strokeWidth
        )

        // 绘制下边框
        drawLine(
            color = Color.Black,
            start = Offset(0f, size.height - inset),
            end = Offset(size.width, size.height - inset),
            strokeWidth = strokeWidth
        )

        // 绘制右边框
        if (drawRight) {
            drawLine(
                color = Color.Black,
                start = Offset(size.width - inset, inset),
                end = Offset(size.width - inset, size.height - inset),
                strokeWidth = strokeWidth
            )
        }
    }
}